import { Component } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { NzInputModule } from 'ng-zorro-antd/input';
import { NzInputNumberModule } from 'ng-zorro-antd/input-number';

@Component({
  selector: 'app-input-number-precision',
  standalone: true,
  imports: [NzInputNumberModule, NzInputModule, FormsModule],
  template: `
    <p class="demo demo-space">
      <nz-input-number
        [(ngModel)]="value1"
        nzMin="0"
        nzMax="10"
        nzStep="0.1"
        [nzPrecision]="1"
      />
      <nz-input-number
        [(ngModel)]="value2"
        nzMin="0"
        nzMax="10"
        nzStep="0.1"
        [nzPrecision]="1"
        nzPrecisionMode="cut"
      />
      <nz-input-number
        [(ngModel)]="value2"
        nzMin="0"
        nzMax="10"
        nzStep="0.5"
        [nzPrecision]="1"
        [nzPrecisionMode]="strictStep"
      />
    </p>
  `,
})
export class InputNumberPrecisionComponent {
  value1: number | '' = '';
  value2: number | '' = '';
  value3: number | '' = '';
  strictStep = (value: number | string): number => {
    const numberValue = Number(value);
    const times = Math.floor(numberValue / 0.5);
    return times * 0.5;
  };
}
